package com.joker.demo.core.domain.dto;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * 线程池监控数据传输对象
 * 
 * 用于封装线程池的监控信息，包括：
 * 1. 线程池基本状态信息
 * 2. 内存使用情况
 * 3. 线程堆栈信息
 * 4. 任务执行统计
 * 
 * @author : feixiang.li
 * @since : 2025-01-27 10:00
 */
public class ThreadPoolMonitorDTO implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 执行器标识
     */
    private String registerKey;

    /**
     * 应用名称
     */
    private String appName;

    /**
     * 监控时间戳
     */
    private long timestamp;

    /**
     * 线程池基本信息
     */
    private ThreadPoolInfo threadPoolInfo;

    /**
     * 内存使用信息
     */
    private MemoryInfo memoryInfo;

    /**
     * 线程堆栈信息
     */
    private List<ThreadStackInfo> threadStackInfos;

    /**
     * 任务执行统计
     */
    private TaskStatistics taskStatistics;

    @Override
    public String toString() {
        return "ThreadPoolMonitorDTO{" +
                "registerKey='" + registerKey + '\'' +
                ", appName='" + appName + '\'' +
                ", timestamp=" + timestamp +
                ", threadPoolInfo=" + threadPoolInfo +
                ", memoryInfo=" + memoryInfo +
                ", threadStackInfos=" + threadStackInfos +
                ", taskStatistics=" + taskStatistics +
                '}';
    }

    /**
     * 线程池基本信息
     */
    public static class ThreadPoolInfo implements Serializable {
        
        /**
         * 核心线程数
         */
        private int corePoolSize;
        
        /**
         * 最大线程数
         */
        private int maximumPoolSize;
        
        /**
         * 当前线程池大小
         */
        private int poolSize;
        
        /**
         * 活跃线程数
         */
        private int activeCount;
        
        /**
         * 队列大小
         */
        private int queueSize;
        
        /**
         * 队列剩余容量
         */
        private int queueRemainingCapacity;
        
        /**
         * 已完成任务数
         */
        private long completedTaskCount;
        
        /**
         * 总任务数
         */
        private long taskCount;

        // getters and setters
        public int getCorePoolSize() {
            return corePoolSize;
        }

        public void setCorePoolSize(int corePoolSize) {
            this.corePoolSize = corePoolSize;
        }

        public int getMaximumPoolSize() {
            return maximumPoolSize;
        }

        public void setMaximumPoolSize(int maximumPoolSize) {
            this.maximumPoolSize = maximumPoolSize;
        }

        public int getPoolSize() {
            return poolSize;
        }

        public void setPoolSize(int poolSize) {
            this.poolSize = poolSize;
        }

        public int getActiveCount() {
            return activeCount;
        }

        public void setActiveCount(int activeCount) {
            this.activeCount = activeCount;
        }

        public int getQueueSize() {
            return queueSize;
        }

        public void setQueueSize(int queueSize) {
            this.queueSize = queueSize;
        }

        public int getQueueRemainingCapacity() {
            return queueRemainingCapacity;
        }

        public void setQueueRemainingCapacity(int queueRemainingCapacity) {
            this.queueRemainingCapacity = queueRemainingCapacity;
        }

        public long getCompletedTaskCount() {
            return completedTaskCount;
        }

        public void setCompletedTaskCount(long completedTaskCount) {
            this.completedTaskCount = completedTaskCount;
        }

        public long getTaskCount() {
            return taskCount;
        }

        public void setTaskCount(long taskCount) {
            this.taskCount = taskCount;
        }

        @Override
        public String toString() {
            return "ThreadPoolInfo{" +
                    "corePoolSize=" + corePoolSize +
                    ", maximumPoolSize=" + maximumPoolSize +
                    ", poolSize=" + poolSize +
                    ", activeCount=" + activeCount +
                    ", queueSize=" + queueSize +
                    ", queueRemainingCapacity=" + queueRemainingCapacity +
                    ", completedTaskCount=" + completedTaskCount +
                    ", taskCount=" + taskCount +
                    '}';
        }
    }

    /**
     * 内存使用信息
     */
    public static class MemoryInfo implements Serializable {
        
        /**
         * 最大内存（MB）
         */
        private long maxMemoryMB;
        
        /**
         * 已分配内存（MB）
         */
        private long totalMemoryMB;
        
        /**
         * 已使用内存（MB）
         */
        private long usedMemoryMB;
        
        /**
         * 空闲内存（MB）
         */
        private long freeMemoryMB;
        
        /**
         * 内存使用率（%）
         */
        private double memoryUsagePercent;

        // getters and setters
        public long getMaxMemoryMB() {
            return maxMemoryMB;
        }

        public void setMaxMemoryMB(long maxMemoryMB) {
            this.maxMemoryMB = maxMemoryMB;
        }

        public long getTotalMemoryMB() {
            return totalMemoryMB;
        }

        public void setTotalMemoryMB(long totalMemoryMB) {
            this.totalMemoryMB = totalMemoryMB;
        }

        public long getUsedMemoryMB() {
            return usedMemoryMB;
        }

        public void setUsedMemoryMB(long usedMemoryMB) {
            this.usedMemoryMB = usedMemoryMB;
        }

        public long getFreeMemoryMB() {
            return freeMemoryMB;
        }

        public void setFreeMemoryMB(long freeMemoryMB) {
            this.freeMemoryMB = freeMemoryMB;
        }

        public double getMemoryUsagePercent() {
            return memoryUsagePercent;
        }

        public void setMemoryUsagePercent(double memoryUsagePercent) {
            this.memoryUsagePercent = memoryUsagePercent;
        }

        @Override
        public String toString() {
            return "MemoryInfo{" +
                    "maxMemoryMB=" + maxMemoryMB +
                    ", totalMemoryMB=" + totalMemoryMB +
                    ", usedMemoryMB=" + usedMemoryMB +
                    ", freeMemoryMB=" + freeMemoryMB +
                    ", memoryUsagePercent=" + memoryUsagePercent +
                    '}';
        }
    }

    /**
     * 线程堆栈信息
     */
    public static class ThreadStackInfo implements Serializable {
        
        /**
         * 线程ID
         */
        private long threadId;
        
        /**
         * 线程名称
         */
        private String threadName;
        
        /**
         * 线程状态
         */
        private String threadState;
        
        /**
         * 是否守护线程
         */
        private boolean daemon;
        
        /**
         * 线程优先级
         */
        private int priority;
        
        /**
         * 堆栈信息
         */
        private String stackTrace;
        
        /**
         * 当前执行的任务信息
         */
        private String currentTask;

        // getters and setters
        public long getThreadId() {
            return threadId;
        }

        public void setThreadId(long threadId) {
            this.threadId = threadId;
        }

        public String getThreadName() {
            return threadName;
        }

        public void setThreadName(String threadName) {
            this.threadName = threadName;
        }

        public String getThreadState() {
            return threadState;
        }

        public void setThreadState(String threadState) {
            this.threadState = threadState;
        }

        public boolean isDaemon() {
            return daemon;
        }

        public void setDaemon(boolean daemon) {
            this.daemon = daemon;
        }

        public int getPriority() {
            return priority;
        }

        public void setPriority(int priority) {
            this.priority = priority;
        }

        public String getStackTrace() {
            return stackTrace;
        }

        public void setStackTrace(String stackTrace) {
            this.stackTrace = stackTrace;
        }

        public String getCurrentTask() {
            return currentTask;
        }

        public void setCurrentTask(String currentTask) {
            this.currentTask = currentTask;
        }

        @Override
        public String toString() {
            return "ThreadStackInfo{" +
                    "threadId=" + threadId +
                    ", threadName='" + threadName + '\'' +
                    ", threadState='" + threadState + '\'' +
                    ", daemon=" + daemon +
                    ", priority=" + priority +
                    ", stackTrace='" + stackTrace + '\'' +
                    ", currentTask='" + currentTask + '\'' +
                    '}';
        }
    }

    /**
     * 任务执行统计
     */
    public static class TaskStatistics implements Serializable {
        
        /**
         * 当前运行中的任务数
         */
        private int runningTaskCount;
        
        /**
         * 延迟任务数
         */
        private int delayTaskCount;
        
        /**
         * 最近一分钟完成的任务数
         */
        private long completedTasksLastMinute;
        
        /**
         * 最近一分钟失败的任务数
         */
        private long failedTasksLastMinute;
        
        /**
         * 平均任务执行时间（毫秒）
         */
        private double averageTaskExecutionTimeMs;

        // getters and setters
        public int getRunningTaskCount() {
            return runningTaskCount;
        }

        public void setRunningTaskCount(int runningTaskCount) {
            this.runningTaskCount = runningTaskCount;
        }

        public int getDelayTaskCount() {
            return delayTaskCount;
        }

        public void setDelayTaskCount(int delayTaskCount) {
            this.delayTaskCount = delayTaskCount;
        }

        public long getCompletedTasksLastMinute() {
            return completedTasksLastMinute;
        }

        public void setCompletedTasksLastMinute(long completedTasksLastMinute) {
            this.completedTasksLastMinute = completedTasksLastMinute;
        }

        public long getFailedTasksLastMinute() {
            return failedTasksLastMinute;
        }

        public void setFailedTasksLastMinute(long failedTasksLastMinute) {
            this.failedTasksLastMinute = failedTasksLastMinute;
        }

        public double getAverageTaskExecutionTimeMs() {
            return averageTaskExecutionTimeMs;
        }

        public void setAverageTaskExecutionTimeMs(double averageTaskExecutionTimeMs) {
            this.averageTaskExecutionTimeMs = averageTaskExecutionTimeMs;
        }

        @Override
        public String toString() {
            return "TaskStatistics{" +
                    "runningTaskCount=" + runningTaskCount +
                    ", delayTaskCount=" + delayTaskCount +
                    ", completedTasksLastMinute=" + completedTasksLastMinute +
                    ", failedTasksLastMinute=" + failedTasksLastMinute +
                    ", averageTaskExecutionTimeMs=" + averageTaskExecutionTimeMs +
                    '}';
        }
    }

    // getters and setters
    public String getRegisterKey() {
        return registerKey;
    }

    public void setRegisterKey(String registerKey) {
        this.registerKey = registerKey;
    }

    public String getAppName() {
        return appName;
    }

    public void setAppName(String appName) {
        this.appName = appName;
    }

    public long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }

    public ThreadPoolInfo getThreadPoolInfo() {
        return threadPoolInfo;
    }

    public void setThreadPoolInfo(ThreadPoolInfo threadPoolInfo) {
        this.threadPoolInfo = threadPoolInfo;
    }

    public MemoryInfo getMemoryInfo() {
        return memoryInfo;
    }

    public void setMemoryInfo(MemoryInfo memoryInfo) {
        this.memoryInfo = memoryInfo;
    }

    public List<ThreadStackInfo> getThreadStackInfos() {
        return threadStackInfos;
    }

    public void setThreadStackInfos(List<ThreadStackInfo> threadStackInfos) {
        this.threadStackInfos = threadStackInfos;
    }

    public TaskStatistics getTaskStatistics() {
        return taskStatistics;
    }

    public void setTaskStatistics(TaskStatistics taskStatistics) {
        this.taskStatistics = taskStatistics;
    }

}
